home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
print
/
gsview10.zip
/
dialog.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-06
|
19KB
|
638 lines
/*
* dialog.c -- General dialog boxes for GSVIEW.EXE,
* a graphical interface for MS-Windows Ghostscript
* Copyright (C) 1993 Russell Lang
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Russell Lang
* Internet: rjl@monu1.cc.monash.edu.au
*/
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <commdlg.h>
#include <shellapi.h>
#include <mmsystem.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <dir.h>
#include <io.h>
#define NeedFunctionPrototypes 1
#include "ps.h"
#include "gsview.h"
BOOL
getfilename(LPSTR filename, BOOL save, UINT filter, UINT title, UINT help)
{
LPSTR old_lpstrFile;
LPCSTR old_lpstrTitle;
char szTitle[MAXSTR];
BOOL flag;
if (help)
LoadString(phInstance, help, szHelpTopic, sizeof(szHelpTopic));
old_lpstrTitle = ofn.lpstrTitle;
if (title) {
LoadString(phInstance, title, szTitle, sizeof(szTitle));
ofn.lpstrTitle = (LPCSTR)szTitle;
}
old_lpstrFile = ofn.lpstrFile;
if (filename != (LPSTR)NULL)
ofn.lpstrFile = filename;
ofn.nFilterIndex = filter;
if (save)
flag = GetSaveFileName(&ofn);
else
flag = GetOpenFileName(&ofn);
ofn.lpstrTitle = old_lpstrTitle;
ofn.lpstrFile = old_lpstrFile;
ofn.nFilterIndex = FILTER_PS;
if ( save && flag &&
(dfname[0]!='\0') && (lstrcmp(filename, dfname) == 0) ) {
gserror(IDS_NOTDFNAME, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
flag = FALSE;
}
return flag;
}
/* Input Dialog Box structures */
LPSTR input_prop = "input_prop";
struct input_param {
LPSTR prompt;
LPSTR answer;
};
BOOL
get_string(char *prompt, char *answer)
{
struct input_param param;
DLGPROC lpProcInput;
BOOL flag;
param.answer = answer;
param.prompt = prompt;
lpProcInput = (DLGPROC)MakeProcInstance((FARPROC)InputDlgProc, phInstance);
flag = DialogBoxParam( phInstance, "InputDlgBox", hwndimg, lpProcInput, (LPARAM)¶m);
FreeProcInstance((FARPROC)lpProcInput);
return flag;
}
/* input string dialog box */
BOOL CALLBACK _export
InputDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_INITDIALOG:
{
HLOCAL hlocal;
LPSTR *panswer;
struct input_param *pparam = (struct input_param *)lParam;
SetDlgItemText(hDlg, ID_PROMPT, pparam->prompt);
SetDlgItemText(hDlg, ID_ANSWER, pparam->answer);
/* save address of answer string in property list */
hlocal = LocalAlloc(LHND, sizeof(pparam->answer));
panswer = (LPSTR *)LocalLock(hlocal);
if (panswer != (LPSTR *)NULL) {
*panswer = pparam->answer;
LocalUnlock(hlocal);
SetProp(hDlg, input_prop, (HANDLE)hlocal);
}
}
return( TRUE);
case WM_COMMAND:
switch(LOWORD(wParam)) {
case ID_HELP:
SendMessage(hwndimg, help_message, 0, 0L);
return(FALSE);
case ID_ANSWER:
return(TRUE);
case IDOK:
{
HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop);
LPSTR *panswer;
panswer = (LPSTR *)LocalLock(hlocal);
if (panswer != (LPSTR *)NULL) {
GetDlgItemText(hDlg, ID_ANSWER, *panswer, MAXSTR);
LocalUnlock(hlocal);
}
LocalFree(hlocal);
RemoveProp(hDlg, input_prop);
}
EndDialog(hDlg, TRUE);
return(TRUE);
case IDCANCEL:
{
HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop);
LocalFree(hlocal);
RemoveProp(hDlg, input_prop);
}
EndDialog(hDlg, FALSE);
return(TRUE);
default:
return(FALSE);
}
default:
return(FALSE);
}
}
/* copyright dialog box */
BOOL CALLBACK _export
AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_INITDIALOG:
SetDlgItemText(hDlg, ABOUT_VERSION, GSVIEW_VERSION);
return( TRUE);
case WM_LBUTTONDBLCLK:
{DWORD dwUnit = GetDialogBaseUnits();
RECT rect; POINT pt;
pt.x = LOWORD(lParam); pt.y = HIWORD(lParam);
rect.left = 8 * LOWORD(dwUnit) / 4;
rect.top = 138 * HIWORD(dwUnit) / 8;
rect.right = 240 * LOWORD(dwUnit) / 4 + rect.left;
rect.bottom = 8 * HIWORD(dwUnit) / 8 + rect.top;
if (PtInRect(&rect,pt)) {
BITMAP bm;
HBITMAP hbitmap_old;
HBITMAP hbitmap = LoadBitmap(phInstance,"gsview_bitmap");
HDC hdc = GetDC(hDlg);
HDC hdcsrc = CreateCompatibleDC(hdc);
hbitmap_old = SelectObject(hdcsrc,hbitmap);
GetObject(hbitmap, sizeof(BITMAP),&bm);
BitBlt(hdc, rect.right-bm.bmWidth,rect.bottom-bm.bmHeight,
bm.bmWidth,bm.bmHeight,hdcsrc,0,0,SRCCOPY);
SelectObject(hdcsrc,hbitmap_old);
DeleteObject(hbitmap);
DeleteDC(hdcsrc);
ReleaseDC(hDlg,hdc);
}
}
return FALSE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
EndDialog(hDlg, TRUE);
return(TRUE);
default:
return(FALSE);
}
default:
return(FALSE);
}
}
/* information about document dialog box */
BOOL CALLBACK _export
InfoDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_INITDIALOG:
{ char buf[MAXSTR];
int n;
if (dfname[0] != '\0') {
SetDlgItemText(hDlg, INFO_FILE, dfname);
if (doc) {
if (is_ctrld)
LoadString(phInstance, IDS_NOTDSC, buf, sizeof(buf));
else {
if (doc->epsf) {
switch (preview) {
case IDS_EPSI:
LoadString(phInstance, IDS_EPSI, buf, sizeof(buf));
break;
case IDS_EPST:
LoadString(phInstance, IDS_EPST, buf, sizeof(buf));
break;
case IDS_EPSW:
LoadString(phInstance, IDS_EPSW, buf, sizeof(buf));
break;
default:
LoadString(phInstance, IDS_EPSF, buf, sizeof(buf));
}
}
else
LoadString(phInstance, IDS_DSC, buf, sizeof(buf));
}
SetDlgItemText(hDlg, INFO_TYPE, buf);
SetDlgItemText(hDlg, INFO_TITLE, doc->title ? doc->title : "");
SetDlgItemText(hDlg, INFO_DATE, doc->date ? doc->date : "");
sprintf(buf, "%d %d %d %d", doc->boundingbox[LLX], doc->boundingbox[LLY],
doc->boundingbox[URX], doc->boundingbox[URY]);
SetDlgItemText(hDlg, INFO_BBOX, buf);
switch(doc->orientation) {
case LANDSCAPE:
LoadString(phInstance, IDS_LANDSCAPE, buf, sizeof(buf));
break;
case PORTRAIT:
LoadString(phInstance, IDS_PORTRAIT, buf, sizeof(buf));
break;
default:
buf[0] = '\0';
}
SetDlgItemText(hDlg, INFO_ORIENT, buf);
switch(doc->pageorder) {
case ASCEND:
LoadString(phInstance, IDS_ASCEND, buf, sizeof(buf));
break;
case DESCEND:
LoadString(phInstance, IDS_DESCEND, buf, sizeof(buf));
break;
case SPECIAL:
LoadString(phInstance, IDS_SPECIAL, buf, sizeof(buf));
break;
default:
buf[0] = '\0';
}
SetDlgItemText(hDlg, INFO_ORDER, buf);
if (doc->default_page_media && doc->default_page_media->name) {
sprintf(buf,"%s %d %d",doc->default_page_media->n